package com.bookmarket.controller;

import com.bookmarket.entity.Btype;
import com.bookmarket.entity.Custom_Discount;
import com.bookmarket.entity.Discount;
import com.bookmarket.entity.Stype;
import com.bookmarket.service.LLBookService;
import com.bookmarket.service.CzgIIndexTopService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Chen Zhaoguang
 * @date 2018/1/5 14:55
 */
@Controller
@RequestMapping("/czgIndexTop")
public class CzgIndexTopController {

    @Resource
    private CzgIIndexTopService czgIndexTopService;
    @Resource
    private LLBookService bookService;
    //获取大类型导航
    @RequestMapping("/getBtype")
    public ModelAndView toIndex(){
        ModelAndView mv = new ModelAndView();
        List<Btype> list = bookService.getallbtype();
        mv.addObject("btypelist",list);
        List<Stype> list1 = bookService.getAllStype();
        mv.addObject("stypelist",list1);
//        List<Stype> list1 = bookService.getstype(id);
//        mv.addObject("stypelist",list1);
        mv.setViewName("stage/Czg_index_top");
        return mv;
    }
    //查询有效优惠券
    @RequestMapping("/Discount")
    public ModelAndView Discount(){
        ModelAndView mv = new ModelAndView();
        List<Discount> list = czgIndexTopService.getAllDiscount();
        mv.addObject("discountlist",list);
        mv.setViewName("stage/CzgDiscountAll");
        return mv;
    }

    @RequestMapping("/OldDiscount")
    public ModelAndView OldDiscount(int custom_id){
        ModelAndView mv = new ModelAndView();
        List<Integer> list= (List<Integer>) czgIndexTopService.getTwoId(custom_id);
        for (Integer i:list) {
            System.out.println(i);
        }
        mv.addObject("idList",list);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    //领取优惠券后余数减1
//    @RequestMapping("/reEnd")
//    public ModelAndView reEnd(Discount discount){
//        ModelAndView mv = new ModelAndView();
//        czgIndexTopService.reEnd(discount);
//        mv.setView(new MappingJackson2JsonView());
//        return mv;
//    }
    //领取优惠券并余数减1
    @RequestMapping("/insertCd")
    public ModelAndView insertCd(int activeId,int customId){
        ModelAndView mv = new ModelAndView();
        czgIndexTopService.insertCd(activeId,customId);
        czgIndexTopService.reEnd(activeId);
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }


    public LLBookService getBookService() {
        return bookService;
    }

    public void setBookService(LLBookService bookService) {
        this.bookService = bookService;
    }

    public CzgIIndexTopService getCzgIndexTopService() {
        return czgIndexTopService;
    }

    public void setCzgIndexTopService(CzgIIndexTopService czgIndexTopService) {
        this.czgIndexTopService = czgIndexTopService;
    }
}
